package com.yuan.miaosha_activity;

import com.yuan.miaosha_activity.dao.MiaoshaActivityDao;
import com.yuan.miaosha_activity.entity.MiaoshaActivityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AppRun implements ApplicationRunner {
    @Autowired
    private MiaoshaActivityDao miaoshaActivityDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<MiaoshaActivityEntity> list = miaoshaActivityDao.selectList(null);
        for (MiaoshaActivityEntity miaoshaActivityEntity : list) {
            redisTemplate.opsForValue().set("goods"+miaoshaActivityEntity.getGoodsId(),miaoshaActivityEntity.getStockCount()+"");
        }
    }
}
